package com.itheima.blog.admin.controller;


import com.itheima.blog.admin.service.ITCategoryService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.itheima.blog.admin.aop.MyLog;
import com.itheima.blog.admin.dto.CategoryQuery;
import com.itheima.blog.admin.entity.TCategory;
import com.itheima.blog.admin.service.ITCategoryService;
import com.itheima.common.domain.R;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 博客分类表 前端控制器
 * </p>
 *
 * @author blog
 * @since 2023-07-11
 */
@Slf4j
@RestController
@RequestMapping("/category")
@RequiredArgsConstructor
public  class TCategoryController {
    private final ITCategoryService categoryService;


    @GetMapping("/page")
    @ApiOperation("分页搜搜索博客")
    //搜索字段：分类名；排序：置顶优先、点击量次之
    public R findPage(@RequestBody CategoryQuery categoryQuery){
        return R.ok(categoryService.findPage(categoryQuery));
    }

    @MyLog(value = "新增博客分类")
    @PostMapping
    @ApiOperation("新增博客分类")
    public void addCategory(@RequestBody TCategory categoryDTO){
        categoryService.addCategory(categoryDTO);
    }


    @MyLog(value = "修改博客分类")
    @PutMapping("/{category}")
    @ApiOperation("修改博客分类")
    private void updateCategory(@RequestBody TCategory categoryDTO){
        log.info(categoryDTO.getName());
        categoryService.updateCategory(categoryDTO);

    }


    @GetMapping("/list")
    @ApiOperation("分类列表")
    public List<String> contributeForLastYear() {
        return categoryService.contributeForLastYear();
    }
}
